<template>
	<view class="withdraw">
		<view class="withdraw-1">
			<view class="withdraw-1-info" v-if="walletInfo.alipay_sn">
				<view>提现人 ：<view>{{walletInfo.real_name}}</view></view>
				<view>支付宝 ：<view>{{walletInfo.alipay_sn}}</view></view>
			</view>
			<navigator class="navigator" url="/pages/my/bind-alipay/bind-alipay-form" v-else>
				<view style="color: #FF0000; font-size: 24rpx; padding: 30rpx 0;">您还没有绑定支付宝账号，请先绑定支付宝账号</view>
				<image src="https://master.shengejiaju.cn/web/static/icons/ico_more_goods@2x.png" v-if="!walletInfo.alipay_sn"></image>
			</navigator>
		</view>
		<view class="withdraw-2">
			<view class="withdraw-2-tit">提现金额</view>
			<view class="withdraw-2-input"><text>¥</text><input type="digit" v-model="form.money" @input="withdrawInput"></view>
			<view class="withdraw-2-tips">
				<view v-if="!Exceed">当前可提现金额：{{walletInfo.money}}元 <text @click="all" v-if="walletInfo.money > 0">全部提现</text></view>
				<view style="color: #F91313;" v-else>超过可提现余额</view>
			</view>
		</view>
		<view class="withdraw-3">
			<navigator url="/pages/my/withdraw-history/withdraw-history">提现历史<image src="https://master.shengejiaju.cn/web/static/icons/ico_more_goods@2x.png"></image></navigator>
		</view>
		<view class="withdraw-btn"><button type="primary" :disabled="walletInfo.alipay_sn&&form.money>0&&!Exceed?false:true" @click="confirm">确认提现</button></view>
		
		<uni-popup ref="password">
			<view class="withdraw-password-valid">
				<image src="https://master.shengejiaju.cn/web/static/icons/ico_close@2x.png" @click="close"></image>
				<view class="withdraw-password-valid-title">请输入提现密码</view>
				<validcode :maxlength="6" :isPwd="true" :focus="false" @finish="getCodeNumber" class="enter-code-box"></validcode>
			</view>
		</uni-popup>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					pay_client:
					// #ifdef MP-WEIXIN
					1,
					// #endif
					// #ifdef APP-PLUS
					2,
					// #endif
					//#ifdef H5
					3,
					// #endif
					money: '',
					privat_key: ''
				},
				walletInfo: {},
				Exceed: false
			};
		},
		onLoad(opstions){
			
		},
		onShow(){
			this.init()
			if(this.$refs.password){
				this.form.money = ''
				this.$refs.password.close()
			}
		},
		mounted(){
			this.$refs.password.close()
		},
		methods: {
			init(){
				this.$api.MyWallet().then(res => {
					this.walletInfo = res.datas
				})
			},
			all(){
				this.form.money = this.walletInfo.money
			},
			withdrawInput(e){
				if(e.detail.value > this.walletInfo.money){
					this.Exceed = true
				}else{
					this.Exceed = false
				}
			},
			confirm(){
				if(!this.walletInfo.privat_key){
					uni.showModal({
						title: '温馨提示',
						content: '您还没有设置提现密码，请设置提现密码后再申请提现',
						confirmText: '立即设置',
						cancelText: '取消',
						success(res) {
							if(res.confirm){
								setTimeout(() => {
									uni.navigateTo({
										url: '/pages/my/withdraw-password/verify-phone'
									})
								},1500)
							}
						}
					})
				}else{
					this.$refs.password.open()
				}
			},
			getCodeNumber(e){
				uni.hideKeyboard()
				uni.showLoading({
					mask: true
				})
				if(e){
					this.form.privat_key = e
					this.$api.WalletWithdrawal(this.form).then(res => {
						uni.showToast({
							icon: 'none',
							title: '提现申请成功',
							duration: 1500
						})
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/my/success/success?money='+this.form.money
							})
						},1500)
					})
				}
			},
			close(){
				this.$refs.password.close()
			}
		}
	}
</script>

<style lang="scss">
	.withdraw{
		padding-top: 20rpx;
		.withdraw-1{
			background-color: #FFF;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.navigator{
				flex: 1;
				padding: 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}
			.withdraw-1-info{
				flex: 1;
				padding: 20rpx;
				view{
					margin-top: 20rpx;
					view{
						display: inline-block;
						color: #666;
					}
					&:first-child{
						margin-top: 0;
					}
				}
			}
			image{
				width: 12rpx;
				height: 20rpx;
			}
		}
		.withdraw-2{
			background-color: #FFF;
			padding: 50rpx 20rpx 0 20rpx;
			margin-top: 20rpx;
			.withdraw-2-tit{
				font-size: 32rpx;
				color: #666;
				margin-bottom: 100rpx;
			}
			.withdraw-2-input{
				display: flex;
				align-items: center;
				border-bottom: solid 1px #EEE;
				text{
					font-size: 50rpx;
					padding-top: 20rpx;
				}
				input{
					display: inline-block;
					font-size: 80rpx;
					height: 80rpx;
					line-height: 80rpx;
					font-family: PingFang SC;
					margin-left: 20rpx;
				}
			}
			.withdraw-2-tips{
				height: 80rpx;
				line-height: 80rpx;
				font-size: 26rpx;
				color: #999;
				text{
					color: #2073F5;
					margin-left: 30rpx;
				}
			}
		}
		.withdraw-3{
			margin-top: 20rpx;
			navigator{
				background-color: #FFF;
				padding: 40rpx 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				image{
					width: 12rpx;
					height: 20rpx;
				}
			}
		}
		.withdraw-btn{
			padding: 80rpx 75rpx;
			button{
				border-radius: 100rpx;
				background-color: #2073F5;
				height: 100rpx;
				line-height: 100rpx;
				font-size: 36rpx;
			}
		}
		.withdraw-password-valid{
			background-color: #FFF;
			width: 630rpx;
			position: relative;
			padding: 0 25rpx 60rpx;
			border-radius: 20rpx;
			image{
				position: absolute;
				right: 20rpx;
				top: 20rpx;
				width: 60rpx;
				height: 60rpx;
			}
			.withdraw-password-valid-title{
				padding: 50rpx 0 30rpx;
				text-align: center;
				font-size: 36rpx;
			}
		}
	}
</style>